<?php global $setting;?>
<script type="text/javascript">
var ban_list = [];
$(document).ready(function() {
	var data = JSON.parse($(".s_temple_setting.home_settings").html());
	$.each(data.data.display_in_profile_card,
	function(index, value) {
		setCheckbox(value, "d_");
	});
	setRadiobox(data.data.allow_commit, "c_");
	setRadiobox(data.data.allow_leave_message, "l_");
	$.each(data.data.ban_list,
	function(index, value) {
		addBanList(data.detialban[value]);
	});
 	reloadListener();
	bindAjaxForm($("#s_s_home_editform"), s_s_home_onSuccess, s_s_home_onError, "s_s_home_dia");
	
});
function search_submit() {
    searchInForm($(".s_ajax_search_in_form"));
    $("#s_ajax_search_input").val("");
}
function dealSearchResult(code, message, data) {
	if(setting_card!="setting_home"){return;}
    if (code != 0) {
        $("#s_ajax_search_field").addClass("error");
        $("#s_ajax_search_input").attr("placeholder", message);
    } else {
        $("#s_ajax_search_field").removeClass("error");

        if (!addBanList(data.data)) {
            $("#s_ajax_search_field").addClass("error");
            $("#s_ajax_search_input").attr("placeholder", "已经存在于你的禁止列表中了");
            return;
        }
        $("#s_ajax_search_input").attr("placeholder", "添加成功");
    }
}

function s_s_home_onError(data){
	showMessage("s_s_home_setting_message",-101,data);
}
function s_s_home_onSuccess(data){
    try {
        showMessage("s_s_home_setting_message",data["code"], data["message"]);
    } catch(ex) {
    	showMessage("s_s_home_setting_message",-31, data);
    }
}
function reset(){
	 $("#s_ban_list").html("");
	 showMessage("s_s_home_setting_message",code,message);
}
function addBanList(detial) {
    if ($.inArray(detial.uid, ban_list) != -1) {
        return false;
    }
    ban_list[ban_list.length] = detial.uid;
    tr = $("<tr>");
    head = $("<td>");
    operation = $("<td>");
    head.append($("<img>").addClass("ui").addClass("avatar").addClass("image").attr("src", detial.head_image_path));
    head.append($("<span>").html(detial.name));
    var temp = $("#ban_list_option_temple").clone();
    temp.attr("id", "");
    temp.find(".s_ban_list").attr("value", detial.uid);
    temp.find(".s_ban_list").click();
    temp.attr("style", "");
    operation.append(temp);
    tr.append(head);
    tr.append(operation);
    $("#s_ban_list").prepend(tr);
    return true;
}
</script>
<h2>家园信息设定</h2>
<div class="s_temple_setting home_settings"><?php print_json_setting("home_settings");?></div>
<div class="ui message hidden" id="s_s_home_setting_message"></div>
<form class="ui form" id="s_s_home_editform" url="index.php?mod=home&childmod=setting&ajax=ture&op=updatehomesetting">
	<hr />
	<div class="field">
		<label>资料卡里展示的其他项目：</label>
		<div class="ui checkbox">
			<input type="checkbox" name="display_in_profile_card[]" id="d_mail" value="mail" class="hidden"> <label>邮箱</label>
		</div>
	</div>
	<div class="field">
		<div class="ui checkbox">
			<input type="checkbox" name="display_in_profile_card[]" id="d_phone" value="phone" class="hidden"> <label>手机</label>
		</div>
	</div>
	<hr />
	<label>是否允许他人对你留言：</label>
	<div class="inline fields">
		<div class="field">
			<div class="ui radio checkbox" id="student">
				<input type="radio" name="allow_leave_message" id="l_true" value="1" class="hidden"> <label>允许</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox" id="parent">
				<input type="radio" name="allow_leave_message" id="l_false" value="0" class="hidden"> <label>不允许</label>
			</div>
		</div>
	</div>
	<hr />
	<label>是否允许他人对你的动态进行评论：</label>
	<div class="inline fields">
		<div class="field">
			<div class="ui radio checkbox" id="student">
				<input type="radio" name="allow_commit" id="c_true" value="1" class="hidden"> <label>允许</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox" id="parent">
				<input type="radio" name="allow_commit" id="c_false" value="0" class="hidden"> <label>不允许</label>
			</div>
		</div>
	</div>
	<hr />
	<label>禁访列表: </label>
	<div class="ui message">
		<div class="header">提醒</div>
		<p>以下人员将会被禁止访问你的空间（有权限的用户会无视该设定，诸如学生家长->学生，任课教师->学生，或其他设定，具体请咨询站点管理员）</p>
		<p>如果你想取消下面的禁令，请取消勾选后提交，将会自动删除记录。</p>
		<p>如果你想添加其他人，请在文本框内输入uid/手机/邮箱来搜索添加</p>
	</div>
	<div class="s_ajax_search_in_form" url="index.php?mod=home&childmod=setting&ajax=true&op=search_for_ban_list" target="s_ajax_search_input">
		<div class="two fields">
			<div class="field" id="s_ajax_search_field">
				<input type="text" name="account" value="" id="s_ajax_search_input">
			</div>
			<div class="field">
				<button class="ui button" onClick="search_submit();return false;">搜索</button>
			</div>
		</div>
	</div>
	<table class="ui table">
		<thead>
			<tr>
				<th>人员</th>
				<th>是否禁止</th>
			</tr>
		</thead>
		<tbody id="s_ban_list">
		</tbody>
	</table>
	<div class="ui error message"></div>
	<button class="ui button" type="submit">保存</button>
</form>
<div class="ui checkbox" id="ban_list_option_temple" style="display: none;">
	<input type="checkbox" name="ban_list[]" value="0" class="hidden s_ban_list"> <label>禁止</label>
</div>
